//package com.zxx.mvpPractice.model.net.rxmanager;
//
//
//import com.zxx.mvpPractice.model.net.exception.RetryWhenNetworkException;
//
//import java.util.concurrent.TimeUnit;
//
//import okhttp3.OkHttpClient;
//import retrofit2.Retrofit;
//import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
//import retrofit2.converter.gson.GsonConverterFactory;
//import rx.Observable;
//import rx.android.schedulers.AndroidSchedulers;
//import rx.schedulers.Schedulers;
//
///**
// * Created by Administrator on 2017/1/5.
// */
//public class HttpManager {
//
//    private volatile static HttpManager INSTANCE;
//    public static String BASE_URL = "";
//    public static long DEFAULT_TIMEOUT = 0L;
//
//    private HttpManager() {
//        //手动创建一个OkHttpClient并设置超时时间
//        OkHttpClient.Builder builder = new OkHttpClient.Builder();
//        builder.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
//        Retrofit retrofit = new Retrofit.Builder()
//                .client(builder.build())
//                .addConverterFactory(GsonConverterFactory.create())
//                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                .baseUrl(BASE_URL)
//                .build();
//        httpService = retrofit.create(HttpService.class);
//    }
//
//    public static HttpManager getInstance() {
//        if (INSTANCE == null) {
//            synchronized (HttpManager.class) {
//                if (INSTANCE == null) {
//                    INSTANCE = new HttpManager();
//                }
//            }
//        }
//        return INSTANCE;
//    }
//
//    /**
//     * 处理http请求
//     *
//     * @param basePar 封装的请求数据
//     */
//    public void doHttpDeal(BaseEntity basePar) {
//        Observable observable=basePar.getObservable(httpService)
//                /*失败后的retry配置*/
//                .retryWhen(new RetryWhenNetworkException())
//                /*生命周期管理*/
//                .compose(basePar.getRxAppCompatActivity().bindToLifecycle())
//                /*http请求线程*/
//                .subscribeOn(Schedulers.io())
//                .unsubscribeOn(Schedulers.io())
//                /*回调线程*/
//                .observeOn(AndroidSchedulers.mainThread())
//                /*结果判断*/
//                .map(basePar);
//        /*数据回调*/
//        observable.subscribe(basePar.getSubscirber());
//    }
//}
